package com.hxd.mall.module.product.home.active

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hxd.mall.R
import com.hxd.mall.module.product.home.bean.Resource
import com.hxd.mall.utils.open.UIUtil

/**
 * @author zhaoyong
 * @description:
 * @date :2019-10-14 18:54
 */
class ActiveTypeListAdapter(var index: Int, var isReset: Boolean) :
    BaseQuickAdapter<Resource, BaseViewHolder>(R.layout.adapter_active_type_layout) {

    override fun convert(helper: BaseViewHolder?, item: Resource?) {
        helper?.run {
            val textView = itemView.findViewById<TextView>(R.id.tv_type)
            textView.text = item?.title

            if (index == adapterPosition) {
                textView.setTextColor(Color.parseColor("#FFFFFFFF"))
                //defaultRid != null表示是首页进来的，首页不需要设置字体大小
                textView.textSize = 16f
                setGone(R.id.iv_icon, true)
            } else {
                textView.setTextColor(Color.parseColor("#CCFFFFFF"))
                //defaultRid != null表示是首页进来的，首页不需要设置字体大小
                textView.textSize = 14f
                setGone(R.id.iv_icon, false)
            }

            if (isReset) {
                val params = itemView.layoutParams
                params.width = UIUtil.dip2px(110)
                itemView.layoutParams = params
            }
        }
    }
}

class HomeActiveTypeListAdapter(var index: Int, var isReset: Boolean, var color: Int, var drawable: Drawable?) :
    BaseQuickAdapter<Resource, BaseViewHolder>(R.layout.adapter_home_active_type_layout) {

    override fun convert(helper: BaseViewHolder?, item: Resource?) {
        helper?.run {
            val textView = itemView.findViewById<TextView>(R.id.tv_type)
            textView.text = item?.title

            textView.setTextColor(color)

            if (index == adapterPosition) {
                //textView.setTextColor(Color.parseColor("#FFFFFFFF"))
                //defaultRid != null表示是首页进来的，首页不需要设置字体大小
                setVisible(R.id.iv_icon, true)

                val iv_icon = itemView.findViewById<ImageView>(R.id.iv_icon)

                iv_icon.background = drawable ?: ContextCompat.getDrawable(mContext, R.drawable.home_type_bottom_line)
            } else {
                //textView.setTextColor(Color.parseColor("#CCFFFFFF"))
                //defaultRid != null表示是首页进来的，首页不需要设置字体大小
                setVisible(R.id.iv_icon, false)
            }

            if (isReset) {
                val params = itemView.layoutParams
                params.width = UIUtil.dip2px(110)
                itemView.layoutParams = params
            }
        }
    }
}